package org.baitu.zzim.util;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author zhangkai_a
 * @date 2025/7/9 11:02
 */
@Component
public class NodeIdUtil {

    @Value("${server.port}")
    private int port;

    private String ip;

    @PostConstruct
    public void init() throws UnknownHostException {
        this.ip = InetAddress.getLocalHost().getHostAddress();
    }

    public String getNodeId() {
        return ip + ":" + port;
    }

    public String getTopic(String prefix) {
        return prefix + getNodeId(); // e.g., im-chat-node-192.168.1.100:8080
    }

    public String getGroup(String prefix) {
        return prefix + getNodeId();
    }
}